﻿<!DOCTYPE>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <meta http-equiv="content-type" content="txt/html charset=utf-8" />
    <title>热表定时任务维护</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <style type="text/css">
        .panelSection > .panel > .panel-header
        {
            padding-left: 25px;
        }
        #dg .panelSection > .panel > .panel-header
        {
            padding-left: 5px;
        }
        
        .l-btn2
        {
            border: #d2d2d2 1px solid;
            font-family: Tahoma, Helvetica;
            font-size: 10px;
            cursor: pointer;
            font-weight: 500;
            text-decoration: none;
            height: 26px;
            color: #fff;
            background: #02bfbf;
        }
        .l-btn2:hover
        {
            color: #fff;
            background: #05d2d2;
        }
        
        #dvScheduledTaskLog tbody .datagrid-cell
        {
            overlow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .lableTextMu
        {
            float: right;
            font-size: 10px;
        }
    </style>
</head>
<body>
    <div class="panelSection" style="">
        <div class="easyui-panel " title="定时任务管理" style="padding: 3px; width: 100%" data-options="iconCls:'icon-metro-settings',closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div id="dvOperateBtn" style="margin: 0 0 3px 3px">
                <a href="javascript:void(0)" id="mb" class="easyui-menubutton" data-options="menu:'#mm'"
                    style="width: 70px;">新增</a>
                <div id="mm" style="width: 180px;">
                    <div id="addSyncLineData" data-options="iconCls:'icon-add'">
                        同步现场台账</div>
                    <div class="menu-sep">
                    </div>
                    <div id="addPreApsPlan" data-options="iconCls:'icon-add'">
                        预排制造计划（工步）</div>
                    <div class="menu-sep">
                    </div>
                    <div id="addProductCheck" data-options="iconCls:'icon-add'">
                        生产准备检查（工步）</div>
                    <div class="menu-sep">
                    </div>
                    <div id="addApsShipRev" data-options="iconCls:'icon-add'">
                        转工计划接收（工步）</div>
                    <div class="menu-sep">
                    </div>
                    <div id="addApsPlan" data-options="iconCls:'icon-add'">
                        滚动制造计划（工步）</div>
                </div>
                <a href="javascript:void(0);" id="btnEditTask" class="easyui-linkbutton" data-options=""
                    style="margin-left: 10px; width: 60px">编辑</a> <a href="javascript:void(0);" id="btnManualTaskStart"
                        class="easyui-linkbutton" data-options="" style="margin-left: 10px; width: 80px">
                        手工执行</a> <a href="javascript:void(0);" id="btnManualTaskStop" class="easyui-linkbutton"
                            data-options="" style="margin-left: 10px; width: 80px">手工停止</a> <a href="javascript:void(0);"
                                id="btnDelTask" class="easyui-linkbutton" data-options="" style="margin-left: 10px;
                                width: 60px">删除</a> <a href="javascript:void(0);" id="btnOperaDetail" class="easyui-linkbutton"
                                    data-options="" style="margin-left: 10px; width: 80px">操作日志</a>
                                    <a href="javascript:void(0);" id="btnRefresh" class="easyui-linkbutton"
                                    data-options="" style="margin-left: 10px; width: 80px">刷新</a>
            </div>
            <div id="dvScheduledTask" style="">
                <table id="gdScheduledTask" class="easyui-datagrid" style="width: 100%; height: 250px"
                    data-options="rownumbers:true,fitColumns:true,pagination:false,striped:true,checkOnSelect:true,selectOnCheck:true,singleSelect:true,pageNumber:1,pageSize:5,pageList:[5,10,20]">
                </table>
                <div id="pp" style="float: right" class="easyui-pagination" data-options="  
                 layout:['list','first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: true,
                    pageSize:10,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                    pageList:[5,10,20,50,100,200],
                     buttons:[{
                            iconCls:'',
                            text:'Go',
                            group:'paging-tail-btns',
                            id:'pageGo'
                    }]
                ">
                </div>
            </div>
        </div>
    </div>
    <div class="panelSection" style="">
        <div class="easyui-panel " title="定时任务执行日志" style="padding: 3px; width: 100%" data-options="iconCls:'icon-metro-settings',closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div id="dvScheduledTaskLog">
                <table id="dgScheduledTaskLog" class="easyui-datagrid" style="width: 100%; height: 250px"
                    data-options="rownumbers:true,fitColumns:false,pagination:false,striped:true,checkOnSelect:true,selectOnCheck:true,singleSelect:true,pageNumber:1,pageSize:5,pageList:[5,10,20]">
                </table>
            </div>
        </div>
    </div>
    <div id="dg" style="padding: 0 1px 0 0; display: none">
        <div class="panelSection" style="">
            <div class="easyui-panel " title="任务说明" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:false,minimizable:false,maximizable:false,border:false">
                <div id="taskExplain" style="margin: 5px 5px 15px 15px; color: Gray">
                </div>
            </div>
        </div>
        <div class="panelSection" style="">
            <div class="easyui-panel " title="基础配置" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:false,minimizable:false,maximizable:false,border:false">
                <form id="dgBaseForm" action="">
                <div style="margin-left: 0px; float: left">
                    <div class="divLabel" style="width: 100px; margin-top: 10px; text-align: right; display: inline-block">
                        任务名称：</div>
                    <select id="popddlTaskName" class="easyui-combobox" name="taskType" data-options="disabled:true,required:true,panelHeight:100"
                        style="width: 148px; height: 22px">
                        <option value="">请选择</option>
                        <option value="3">同步现场台账</option>
                        <option value="4">预排制造计划（工步）</option>
                        <option value="5">生产准备检查（工步）</option>
                        <option value="6">转工计划接收（工步）</option>
                        <option value="7">滚动制造计划（工步）</option>
                    </select>
                </div>
                <div style="margin-left: 0px; margin-top: 10px; float: left">
                    <div class="divLabel" style="width: 100px; text-align: right; display: inline-block">
                        分厂：</div>
                    <input id="poptxtFactory" name="factory" class="easyui-textbox" type="text" data-options="disabled:true,panelHeight:200,required:true"
                        style="width: 150px; height: 25px" />
                </div>
                <div style="float: left; margin-left: 0px; margin-top: 10px;">
                    <div class="divLabel" style="width: 100px; text-align: right; display: inline-block">
                        开始时间：</div>
                    <input id="poptxtStartDate" name="taskStartDate" type="text" class="easyui-datetimebox"
                        data-options="required:true" style="height: 25px; width: 148px" />
                </div>
                <div style="margin-left: 0px; margin-top: 10px; float: left">
                    <div class="divLabel" style="width: 100px; text-align: right; display: inline-block">
                        重复周期(天)：</div>
                    <input id="txtCycle" name="cycleTime" class="easyui-numberbox" type="text" data-options="panelHeight:200,required:true"
                        style="width: 60px; height: 25px" />
                </div>
                <div style="float: left; margin-left: 0px; margin-top: 10px;">
                    <div class="divLabel" style="width: 100px; text-align: right; display: inline-block">
                        结束日期：</div>
                    <input id="poptxtEndDate" name="taskEndDate" type="text" class="easyui-datetimebox"
                        data-options="required:true" style="height: 25px; width: 148px" />
                </div>
                <div style="margin-left: 0px; margin-top: 8px; float: left">
                    <div class="divLabel" style="width: 100px; text-align: right; display: inline-block">
                        任务描述：</div>
                    <input id="poptxtTaskDesc" name="taskDesc" class="easyui-textbox" type="text" data-options="panelHeight:200,multiline:true"
                        style="width: 148px; height: 30px" />
                </div>
                </form>
            </div>
        </div>
        <div class="panelSection" style="margin-top: 5px" id="divLineForm">
            <div class="easyui-panel " title="任务选项" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:false,minimizable:false,maximizable:false,border:false">
                <form id="dgLineForm" action="">
                <div style="margin-left: 0px; float: left">
                    <div class="divLabel" style="width: 100px; margin-top: 10px; text-align: right; display: inline-block">
                        库房范围：</div>
                    <input id="asRoomRange" name="roomRange" class="easyui-tagbox" style="width: 400px;
                        height: 26px" data-options="required:true" />
                </div>
                </form>
            </div>
        </div>
        <div class="panelSection" style="margin-top: 5px" id="divPreApsForm">
            <div class="easyui-panel " title="任务选项" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:false,minimizable:false,maximizable:false,border:false">
                <form id="dgPreApsForm" action="">
                <div style="margin-left: 0px; float: left">
                    <div class="divLabel" style="width: 100px; margin-top: 10px; text-align: right; display: inline-block">
                        排产池：</div>
                    <input id="asPreApsPool" name="preApsPool" class="easyui-tagbox" style="width: 400px; height: 26px"
                        data-options="required:true" />
                </div>
                <div style="margin-left: 0px; float: left">
                    <div class="divLabel" style="width: 100px; margin-top: 10px; text-align: right; display: inline-block">
                        预排覆盖周期：</div>
                    <input id="asPreApsCoverCycle" name="preApsCoverCycle" class="easyui-numberbox" style="width: 100px; height: 26px"
                        data-options="required:true" />
                        <label style="font-size: 10px;">天</label>
                </div>
                <div style="margin-left: 25px; float: left">
                    <div class="divLabel" style="width: 110px; margin-top: 10px; text-align: right; display: inline-block">
                        连续加工间隔时间：</div>
                    <input id="asContinuityWorkTimeNum" name="continuityWorkTimeNum" class="easyui-numberbox" style="width: 120px; height: 26px"
                        data-options="required:true" /><label style="font-size: 10px;">分钟</label>
                </div>
                <div style="margin-left: 0px; float: left">
                    <div class="divLabel" style="width: 100px; margin-top: 10px; text-align: right; display: inline-block">
                        预排参考：</div>
                    <select id="asPreApsRefer" name = "preApsRefer" class="easyui-combobox" style="width: 400px; height: 26px">
                        <option value="转工计划开始时间">转工计划开始时间</option>
                    </select>
                </div>
                <div style="margin-left: 0px; float: left">
                    <div class="divLabel" style="width: 100px; margin-top: 10px; text-align: right; display: inline-block">
                        预警规则：</div>
                    <input id="asPreWarningRule" name="preWarningRule" class="easyui-tagbox" style="width: 400px; height: 26px"
                        data-options="required:true" />
                </div>
                <div style="margin-left: 0px; float: left">
                    <div class="divLabel" style="width: 100px; margin-top: 10px; text-align: right; display: inline-block">
                        预警检查：</div>
                    <input id="asPreWarningCheck" name="preWarningCheck" class="easyui-tagbox" style="width: 400px; height: 26px"
                        data-options="required:true" />
                </div>
                </form>
            </div>
        </div>
        <div class="panelSection" style="margin-top: 5px" id="divShipRevForm">
            <div class="easyui-panel " title="任务选项" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:false,minimizable:false,maximizable:false,border:false">
                <form id="dgShipRevForm" action="">
                    <div style="margin-left: 0px; float: left">
                        <div class="divLabel" style="width: 100px; margin-top: 10px; text-align: right; display: inline-block">
                            接收参考：</div>
                        <select id="asReceiveRefer" name = "receiveRefer" class="easyui-combobox" style="width: 400px; height: 26px">
                            <option value="转工计划开始时间">转工计划开始时间</option>
                        </select>
                    </div>    
                <div style="margin-left: 0px;margin-top: 10px; float: left">
                    <div class="divLabel" style="width: 100px; margin-top: 10px; text-align: right; display: inline-block">
                        接收后自动开卡：</div>
                    <select id="asRevedStart" name = "revedStart" class="easyui-combobox" style="width: 140px; height: 26px" data-options="panelHeight:100,required:true">
                        <option value="是">是</option>
                        <option value="否">否</option>
                    </select>
                </div>
                <div style="margin-left: 10px; margin-top: 10px;float: left">
                    <div class="divLabel" style="width: 100px; margin-top: 10px; text-align: right; display: inline-block">
                        覆盖周期：</div>
                    <input id="asRevCoverCycle" name="revCoverCycle" class="easyui-numberbox" style="width: 130px; height: 26px"
                        data-options="required:true" />
                    <div class="divLabel" style="width: 10px; margin-top: 10px; text-align: left; display: inline-block">
                            天</div>
                </div>
                <div style="margin-left: 0px;margin-top: 10px; float: left">
                    <div class="divLabel" style="width: 100px; margin-top: 10px; text-align: right; display: inline-block">
                        开卡验证：</div>
                    <div style="float: right;margin-top:10px;height: 50px;width: 400px;">1、转工序无法找到相关子工艺，2、主卡工艺类型为"临时"、"重组工艺"，3、主卡状态为"冻结"，4、主卡订单为"关闭"</div>
                </div>
                </form>
            </div>
        </div>
        <div class="panelSection" style="margin-top: 5px" id="divApsForm">
            <div class="easyui-panel " title="任务选项" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:false,minimizable:false,maximizable:false,border:false">
                <form id="dgApsForm" action="">
                <div style="margin-left: 0px; float: left">
                    <div class="divLabel" style="width: 100px; margin-top: 10px; text-align: right; display: inline-block">
                        覆盖周期：</div>
                    <input id="asApsCoverCycle" name="apsCoverCycle" class="easyui-numberbox" style="width: 120px;
                        height: 26px" data-options="required:true" /><label style="font-size: 10px;">天</label>
                </div>
                 <div style="margin-left: 25px; float: left">
                    <div class="divLabel" style="width: 110px; margin-top: 10px; text-align: right; display: inline-block">
                        连续加工间隔时间：</div>
                    <input id="asApsContinuityWorkTimeNum" name="continuityWorkTimeNum" class="easyui-numberbox" style="width: 120px; height: 26px"
                        data-options="required:true" /><label style="font-size: 10px;">分钟</label>
                </div>
                <div style="margin-left: 0px;margin-top: 10px; float: left">
                    <div class="divLabel" style="width: 100px; margin-top: 10px; text-align: right; display: inline-block">
                        异常预警：</div>
                    <label style="float: right;margin-top:10px;height: 50px;width: 400px;">1、计划结束时间超期，2、工步设备出现异常，3、主卡状态为"冻结"，4、主卡订单为"关闭"</label>
                </div>
                </form>
            </div>
        </div>
        <div style="margin-top: 20px; text-align: right; padding-right: 10px">
            <a href="javascript:void(0);" id="popTaskSave" class="easyui-linkbutton not-custom l-btn2 "
                data-options="" style="margin-left: 0px; width: 60px">确定</a> <a href="javascript:void(0);"
                    id="popTaskCancel" class="easyui-linkbutton not-custom l-btn2 " data-options=""
                    style="margin-left: 10px; width: 60px">取消</a>
        </div>
    </div>
    <div id="dgOperaLog" style="display: none">
        <div class="dvgrid-cellwarp" style="background: #fff; margin: 3px 0px 3px 3px">
            <table id="operaLogTable" class="easyui-datagrid" data-options="rownumbers:true,fitColumns:true">
            </table>
        </div>
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    /*
    创建人：zhangrj
    日期：2024-07-18
    描述：热表定时任务维护js
    */
    var page = {
        pagetotal: 0,
        pageSize: 10,
        pageNumber: 1,
        rootPath: getRootPath(), //网站根路径
        commonUrl: getRootPath() + "/Ashx/CommonHandler.ashx",
        ajaxUrl: getRootPath() + "/Ashx/ApsHandler/ScheduledTaskHandler.ashx",
        ajaxUrlAps: getRootPath() + "/Ashx/ApsHandler/ApsLimitedCapacityHandler.ashx",
        //初始化页面
        init: function () {
            page.bind();
            page.searchData();
            customizedEasyuiPagination('pp'); //定制化分页
        },
        //页面事件绑定
        bind: function () {
            //grid初始化
            $("#gdScheduledTask").datagrid({
                onLoadSuccess: function (data) {
                    $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pagetotal,
                        pageSize: page.pageSize,
                        pageNumber: parseInt(page.pageNumber)
                    });
                    customizedEasyuiPagination('pp'); //定制化分页

                },
                onSelect: function (index, rowData) {
                    page.reset(false, false, true);
                    page.loadScheduledTaskLog(rowData.SCHEDULEDTASKID);
                },
                onCheck: function (index, rowData) {
                    page.reset(false, false, true);

                },
                onUncheck: function (index, rowData) {
                    page.reset(false, false, true);
                },
                onCheckAll: function (index, rowData) {
                    page.reset(false, false, true);
                },
                onUncheckAll: function (index, rowData) {
                    page.reset(false, false, true);
                },
                onClickCell: function (index, field) {

                },
                columns: [[
                 { field: 'ck', title: '选择', checkbox: true, hidden: true },
                 { field: 'TASKNAME', title: '任务名称', width: 120 },
		         { field: 'TASKDESC', title: '任务描述', width: 180 },
		         { field: 'STATUS', title: '运行状态', width: 80, formatter: function (value, row, index) {
		             if (value == "1") {
		                 return "待执行";
		             } else if (value == "2") {
		                 return "执行中";
		             } else if (value == "3") {
		                 return "错误";
		             } else {
		                 return value;
		             }
		         }
		         },
                 { field: 'CYCLETIME', title: '重复周期(天)', width: 120 },
                 { field: 'LASTEXCUTIME', title: '上次运行时间', width: 120 },
                 { field: 'NEXTEXCUTIME', title: '下次运行时间', width: 120 },
                 { field: 'CREATENAME', title: '创建人', width: 80 },
                 { field: 'CREATEDATE', title: '创建时间', width: 120 },
                 { field: 'LASTCHANGENAME', title: '修改人', width: 80 },
                 { field: 'LASTCHANGEDATE', title: '修改时间', width: 120 }

	           ]]

            });
            $("#dgScheduledTaskLog").datagrid({
                onLoadSuccess: function (data) {

                },
                columns: [[
                 { field: 'EXECUTETYPE', title: '执行类型', width: 80, formatter: function (value, row, index) {
                     if (value == "1") { return "自动"; }
                     else if (value == "2") { return "手动"; }
                     else { return value; }
                 }
                 },
		         { field: 'STATUS', title: '运行状态', width: 80, formatter: function (value, row, index) {
		             if (value == "4") {
		                 return "已完成";
		             } else if (value == "2") {
		                 return "执行中";
		             } else if (value == "3") {
		                 return "错误";
		             } else {
		                 return value;
		             }
		         }
		         },
                 { field: 'TASKEXESTARTTIME', title: '任务开始时间', width: 150 },
                 { field: 'DURATION', title: '持续时长', width: 100, formatter: function (value, row, index) {
                     if (!isNullOrWhiteSpaceStr(row.TASKEXESTARTTIME) && !isNullOrWhiteSpaceStr(row.TASKEXEENDTIME)) {
                         var diffMin = dayjs(row.TASKEXEENDTIME).diff(dayjs(row.TASKEXESTARTTIME), 'minute', true);
                         var re = '';
                         re = re + Math.floor(diffMin / 60).toString() + 'H' + Math.round(diffMin % 60).toString() + 'MIN';
                         return re;
                     }
                 }
                 },
                 { field: 'TASKEXEENDTIME', title: '任务结束时间', width: 150 },
                 { field: 'LOGMESSAGE', title: '日志描述', width: 500, formatter: function (value, row, index) {
                     if (isNullOrWhiteSpaceStr(value)) {
                         return value;
                     }
                     var v = value.replace(/[\r\n]/g, "");
                     //prompt("",v);
                     return '<span title=' + v.replace(/[ ]/g, "") + '>' + v + '</span>'
                 }
                 }

	           ]]

            });
            //操作日志表
            $("#operaLogTable").datagrid({
                columns: [[
                 { field: 'TASKNAME', title: '任务名', width: 120 },
		         { field: 'FULLNAME', title: '操作者', width: 80 },
                 { field: 'OPERATIONDATE', title: '操作时间', width: 150, formatter: function (value, row, index) {
                     return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                 }
                 },
                 { field: 'NOTES', title: '操作日志', width: 350 }
	           ]]

            });
            //查询
            $('#btnSearch').on("click", function () {
                page.reset(false, true, true);
                page.pageNumber = 1;
                page.searchData();
            });
            //同步现场台账新增按钮
            $('#addSyncLineData').on("click", function () {
                page.openTaskForm(3, false);
            });
            //预排计划新增按钮
            $('#addPreApsPlan').on("click", function () {
                page.openTaskForm(4, false);
            });
            //生产准备检查新增按钮
            $('#addProductCheck').on("click", function () {
                page.openTaskForm(5, false);
            });
            //转工接收新增按钮
            $('#addApsShipRev').on("click", function () {
                page.openTaskForm(6, false);
            });
            //滚动计划新增按钮
            $('#addApsPlan').on("click", function () {
                page.openTaskForm(7, false);
            });
            //编辑按钮
            $('#btnEditTask').on("click", function () {
                page.openTaskForm(0, true);
            });
            //手工停止
            $('#btnManualTaskStop').on("click", function () {
                page.manualScheduledTaskStop();
            });
            //手工开始
            $('#btnManualTaskStart').on("click", function () {
                page.manualScheduledTaskStart();
            });
            //刷新
            $('#btnRefresh').on("click", function () {
                page.pageNumber = 1;
                page.searchData();
            });

            //删除按钮
            $('#btnDelTask').on("click", function () {
                $.messager.confirm('确认', '确定要删除吗？', function (flag) {
                    if (flag) {
                        page.deleteApsScheduledTask();
                    }
                });

            });
            //操作日志按钮
            $('#btnOperaDetail').on("click", function () {
                page.loadLogData();
            });
            //分页事件
            $('#pp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    customizedEasyuiPagination('pp'); //定制化分页
                    page.pageSize = pageSize; page.pageNumber = pageNumber;
                    page.searchData();
                }
            });
            //绑定分页go按钮
            $('#pageGo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                page.pageNumber = pageNumber;
                page.searchData();
            });
            //清除按钮
            $('#btnReset').on("click", function () {
                page.reset(true, true);
                page.pageNumber = 1; page.pagetotal = 0
                $('#pp').pagination('refresh', {
                    total: page.pagetotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
            });
            //弹窗保存
            $("#popTaskSave").on("click", function () {
                formPage.save();
            });
            //弹窗取消
            $("#popTaskCancel").on("click", function () {
                $('#dg').dialog('close');
            });
        },
        //查询
        searchData: function () {
            var param = {
                action: "searchSTData",
                pageSize: page.pageSize,
                pageNumber: page.pageNumber
            };
            page.post(page.ajaxUrl, param, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, false);
                    return;
                }
                page.pagetotal = res.RowCount;
                $("#gdScheduledTask").datagrid('loadData', { total: res.RowCount, rows: res.DBTable });
            });
        },
        //打开弹窗 
        openDialog: function (height, width) {
            $('#dg').dialog({
                title: '定时任务维护',
                fit: false,
                top: 50,
                width: width,
                height: height,
                closed: false,
                cache: false,
                modal: true,
                returnData: null,
                popupData: null,
                onClose: function () {
                    var re = $("#dg").dialog('options').returnData;
                    if (re != null) {
                        if (re.Result) {
                            page.searchData();
                        }
                    }
                }
            });
        },
        //打开定时任务弹出框（统一的弹窗入口，type：即为定时任务类型，isEdit：是否编辑）
        openTaskForm: function (type, isEdit) {
            var popupData = { selectRow: null, taskType: type };
            if (isEdit) {
                var selectRow = $("#gdScheduledTask").datagrid('getSelected');
                if (selectRow == null) {
                    displayMessage("请选择记录", false);
                    return;
                }
                //执行中状态不能编辑
                if (selectRow.STATUS == '2') {
                    displayMessage("执行中状态不能编辑", false);
                    return;
                }
                popupData.selectRow = selectRow;
                popupData.taskType = selectRow.TASKTYPE;
            }
            if (formPage.initForm(popupData)) {
                switch (popupData.taskType) {
                    case 3: //同步现场台账
                        page.openDialog(400, 570); //打开弹窗（高，宽）
                        break;
                    case 4: //预排制造计划
                        page.openDialog(550, 570); //打开弹窗（高，宽）
                        break;
                    case 5: //生产准备检查
                        page.openDialog(350, 570); //打开弹窗（高，宽）
                        break;
                    case 6: //转工接收
                        page.openDialog(500, 570); //打开弹窗（高，宽）
                        break;
                    case 7: //滚动制造计划
                        page.openDialog(480, 570); //打开弹窗（高，宽）
                        break;
                    default:
                }
            }
        },
        //删除排产定时任务信息
        deleteApsScheduledTask: function () {
            var selectRow = $("#gdScheduledTask").datagrid('getSelected');
            if (selectRow == null) {
                displayMessage("请选择记录", false);
                return;
            }
            //执行中状态不能编辑
            if (selectRow.STATUS == '2') {
                displayMessage("执行中状态不能删除", false);
                return;
            }
            //开始请求后台
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: { action: "deleteApsScheduledTask", scheduledtaskid: selectRow.SCHEDULEDTASKID },
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    //console.log(data);
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    if (result.Result) {
                        displayMessage("删除成功", true);
                        page.searchData();
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }
            });

        },
        //加载定时任务日志
        loadScheduledTaskLog: function (id) {
            var gridID = "#dgScheduledTaskLog";
            var param = {
                action: "loadScheduledTaskLog",
                scheduledtaskid: id
            };
            //console.log(param);
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $(gridID).datagrid('loading');
                },
                success: function (data) {
                    //console.log(data);
                    $(gridID).datagrid('loaded');
                    var result = JSON.parse(data);
                    //console.log(result);
                    if (result.Result) {
                        $(gridID).datagrid('loadData', { total: result.RowCount, rows: result.DBTable });
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $(gridID).datagrid('loaded');
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
        //手工开始
        manualScheduledTaskStart: function () {
            var selectRow = $("#gdScheduledTask").datagrid('getSelected');
            if (selectRow == null) {
                displayMessage("请选择记录", false);
                return;
            }
            //执行中状态不能编辑
            if (!(selectRow.STATUS == '1' || selectRow.STATUS == '3')) {
                displayMessage("只能开始待执行或错误状态的任务", false);
                return;
            }
            var param = { action: "manualScheduledTask", scheduledtaskid: selectRow.SCHEDULEDTASKID, manualtype: 1 };

            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    //console.log(data);
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    //console.log(result);
                    if (result.Result) {
                        page.reset(false, true, true);
                        displayMessage("执行成功", true);
                        page.searchData();
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
        //手工停止
        manualScheduledTaskStop: function () {
            var selectRow = $("#gdScheduledTask").datagrid('getSelected');
            if (selectRow == null) {
                displayMessage("请选择记录", false);
                return;
            }
            //执行中状态不能编辑
            if (selectRow.STATUS != '2') {
                displayMessage("只能停止执行中状态的任务", false);
                return;
            }
            var param = { action: "manualScheduledTask", scheduledtaskid: selectRow.SCHEDULEDTASKID, manualtype: 2 };

            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    //console.log(data);
                    $.messager.progress('close');
                    var result = JSON.parse(data);
                    //console.log(result);
                    if (result.Result) {
                        page.reset(false, true, true);
                        displayMessage("执行成功", true);
                        page.searchData();
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
        //打开操作日志
        loadLogData: function () {
            page.post(page.ajaxUrl, { action: "GetScheduledTaskOperaLog" }, true, function (res) {
                if (res.Result) {
                    $('#dgOperaLog').dialog({
                        title: '操作日志',
                        top: 50,
                        width: '700px',
                        height: '500px',
                        closed: false,
                        cache: false,
                        modal: true,
                        buttons: [{
                            text: '关闭',
                            handler: function () { $('#dgOperaLog').dialog('close'); }
                        }]
                    });
                    $("#operaLogTable").datagrid('loadData', res.DBTable);
                }
            });
        },
        //清除方法，重要！！！
        reset: function (iscondition, isresult, isdetail) {
            clearMessage();
            if (iscondition) {

            }
            if (isresult) {
                clearEasyuiDataGrid("gdScheduledTask");
            }
            if (isdetail) {
                clearEasyuiDataGrid("dgScheduledTaskLog");
            }
        },
        //清空弹窗数据
        resetDialog: function () {
            $("#popddlTaskName").combobox('clear');
            $("#poptxtStartDate").datetimebox('clear');
            $('#poptxtEndDate').datebox('clear');
            $("#poptxtTaskDesc").textbox('clear');
        },
        //POST数据 add by zhangrj 20231031
        post: function (url, params, async, successCallback, errorCallback) {
            $.ajax({
                type: "Post",
                url: url,
                data: params,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (result) {
                    $.messager.progress('close');
                    successCallback(result);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                    if (errorCallback !== undefined) {
                        errorCallback();
                    }
                }
            });
        }
    };
    /*---------
    弹窗对象
    --------*/
    var formPage = {
        selectData: null, //选中行数据
        taskType: 0, //定时任务类型
        //初始化弹窗
        initForm: function (popupData) {
            formPage.selectData = popupData.selectRow;
            formPage.taskType = popupData.taskType;
            formPage.initFormPage(); //初始化页面
            formPage.bind();
            if (formPage.selectData !== null) {
                page.post(page.ajaxUrl, { action: "GetScheduledTaskDetailData", taskType: formPage.taskType, scheduledTaskId: formPage.selectData.SCHEDULEDTASKID }, false, function (result) {
                    if (!result.Result) {
                        displayMessage(result.Message, false);
                        return false;
                    }
                    //基础配置赋值
                    $("#poptxtStartDate").datetimebox('setValue', formPage.selectData.TASKSTARTTIME);
                    $("#poptxtEndDate").datetimebox('setValue', formPage.selectData.TASKENDTIME);
                    $("#poptxtTaskDesc").textbox('setValue', formPage.selectData.TASKDESC);
                    $("#txtCycle").numberbox('setValue', formPage.selectData.CYCLETIME);
                    //任务选项数据绑定
                    if (result.DBTable !== null) {
                        formPage.bindDetailPageData(result.DBTable[0]);
                    }
                }, function () {
                    return false;
                });
            }
            $("#popddlTaskName").combobox('setValue', formPage.taskType);
            $("#poptxtFactory").textbox('setValue', '热表分厂');
            return true;
        },
        //初始化页面内容
        initFormPage: function () {
            $("#popddlTaskName").combobox('clear');
            $("#poptxtStartDate").datetimebox('clear');
            $('#poptxtEndDate').datetimebox('clear');
            $("#poptxtTaskDesc").textbox('clear');
            $("#txtCycle").numberbox('clear');
            switch (formPage.taskType) {
                case 3: //同步现场台账
                    $("#taskExplain").text("根据配置的频率和库房的范围，对工控网MES中的库存台账进行数据同步。");
                    $('#divLineForm').show(); //显示同步现场台账任务选项
                    $('#divPreApsForm').hide(); //隐藏预排制造计划任务选项
                    $('#divShipRevForm').hide(); //隐藏转工计划接收任务选项
                    $('#divApsForm').hide(); //隐藏滚动制造计划任务选项
                    $("#asRoomRange").tagbox('clear');
                    break;
                case 4: //预排制造计划
                    $("#taskExplain").html("根据待接收的转工计划，参考计划开始时间和设备班次、日历进行无限能力正排。<p>*注：无限能力排产时，工步计划开始时间参考设备班次、日历进行连续排产，即单工步加工连续执行。</p>");
                    $('#divLineForm').hide(); //隐藏同步现场台账任务选项
                    $('#divPreApsForm').show(); //显示预排制造计划任务选项
                    $('#divShipRevForm').hide(); //隐藏转工计划接收任务选项
                    $('#divApsForm').hide(); //隐藏滚动制造计划任务选项
                    $("#asPreApsPool").tagbox('clear'); //排产池
                    $("#asContinuityWorkTimeNum").numberbox('clear'); //连续加工间隔时间
                    $('#asPreApsRefer').combobox('clear'); //预排参考
                    $("#asPreApsCoverCycle").numberbox('clear'); //预排覆盖周期
                    $("#asPreWarningRule").tagbox('clear'); //预警规则
                    $("#asPreWarningCheck").tagbox('clear'); //预警检查
                    break;
                case 5: //生产准备检查
                    $("#taskExplain").html("定时将工位生产准备需求安类型、期间和设备，汇总发送到工控");
                    $('#divLineForm').hide(); //隐藏同步现场台账任务选项
                    $('#divPreApsForm').hide(); //隐藏预排制造计划任务选项
                    $('#divShipRevForm').hide(); //隐藏转工计划接收任务选项
                    $('#divApsForm').hide(); //隐藏滚动制造计划任务选项
                    break;
                case 6: //转工计划接收
                    $("#taskExplain").html("根据条件定期接收的转工计划，并获取子工艺自动开卡，若开卡不符合自动");
                    $('#divLineForm').hide(); //隐藏同步现场台账任务选项
                    $('#divPreApsForm').hide(); //隐藏预排制造计划任务选项
                    $('#divShipRevForm').show(); //显示转工计划接收任务选项
                    $('#divApsForm').hide(); //隐藏滚动制造计划任务选项
                    $("#asReceiveRefer").combobox('clear'); //接收参考
                    $("#asRevedStart").combobox('clear'); //接收后自动开卡
                    $('#asRevCoverCycle').numberbox('clear'); //覆盖周期
                    break;
                case 7: //滚动制造计划
                    $("#taskExplain").html("热表厂专用，将各类流水卡汇总到排产池，参考流水卡排产优先级、加工时间长度、计划开始时间、连续加工关系、设备可用情况及设备合炉合批规则，进行有限能力正排。");
                    $('#divLineForm').hide(); //隐藏同步现场台账任务选项
                    $('#divPreApsForm').hide(); //隐藏预排制造计划任务选项
                    $('#divShipRevForm').hide(); //显示转工计划接收任务选项
                    $('#divApsForm').show(); //显示滚动制造计划任务选项
                    $("#asApsCoverCycle").numberbox('clear');
                    $('#asApsContinuityWorkTimeNum').numberbox('clear');
                    break;
                default:
                    break;
            }
        },
        //绑定页面选项数据
        bindDetailPageData: function (datas) {
            switch (formPage.taskType) {
                case 3: //同步现场台账
                    $("#asRoomRange").tagbox('setValues', datas.ROOMRANGE);
                    break;
                case 4: //预排制造计划
                    $("#asPreApsPool").tagbox('setValues', datas.APSPOOL); //排产池
                    $("#asContinuityWorkTimeNum").numberbox('setValue', datas.WORKTIMENUM); //连续加工间隔时间
                    $('#asPreApsRefer').combobox('setValue', datas.APSREFER); //预排参考
                    $("#asPreApsCoverCycle").numberbox('setValue', datas.APSCOVERCYCLE); //预排覆盖周期
                    $("#asPreWarningRule").tagbox('setValues', datas.WARNINGRULE); //预警规则
                    $("#asPreWarningCheck").tagbox('setValues', datas.WARNINGCHECK); //预警检查
                    break;
                case 5: //生产准备检查
                    break;
                case 6: //转工计划接收
                    $("#asReceiveRefer").combobox('setValue', datas.RECEIVEREFER); //接收参考
                    $("#asRevedStart").combobox('setValue', datas.REVEDSTART); //接收后自动开卡
                    $('#asRevCoverCycle').numberbox('setValue', datas.REVCOVERCYCLE); //覆盖周期
                    break;
                case 7: //滚动制造计划
                    $('#asApsCoverCycle').numberbox('setValue', datas.COVERCYCLE); //覆盖周期
                    $('#asApsContinuityWorkTimeNum').numberbox('setValue', datas.WORKTIMENUM); //连续加工间隔时间
                    break;
                default:
                    break;
            }
        },
        //绑定页面事件
        bind: function () {
            switch (formPage.taskType) {
                case 3: //同步现场台账
                    $("#asRoomRange").tagbox({ //初始化库房范围
                        hasDownArrow: true,
                        valueField: 'roomValue',
                        textField: 'roomText',
                        data: [{ 'roomValue': '工装工具库', 'roomText': '工装工具库' }, { 'roomValue': '物料库', 'roomText': '物料库'}]
                    });
                    break;
                case 4: //预排制造计划
                    $("#asPreApsPool").tagbox({ //初始化排产池
                        hasDownArrow: true,
                        valueField: 'Value',
                        textField: 'Text',
                        data: [{ 'Value': '排产池1', 'Text': '排产池1'}]
                    });
                    $("#asPreWarningRule").tagbox({//初始化预警规则
                        hasDownArrow: true,
                        panelHeight: 200,
                        valueField: 'Value',
                        textField: 'Text',
                        data: [{ 'Value': '预排计划结束超转工计划结束', 'Text': '预排计划结束超转工计划结束'}]
                    });
                    $("#asPreWarningCheck").tagbox({//初始化预警检查
                        hasDownArrow: true,
                        panelHeight: 200,
                        valueField: 'Value',
                        textField: 'Text',
                        data: [{ 'Value': '工艺路线', 'Text': '工艺路线' },
                               { 'Value': '排产数据', 'Text': '排产数据' },
                               { 'Value': '工装工具', 'Text': '工装工具' },
                               { 'Value': '设备状态', 'Text': '设备状态' },
                               { 'Value': '生产物资', 'Text': '生产物资' },
                               { 'Value': '特殊过程', 'Text': '特殊过程' }
                            ]
                    });
                    break;
                case 5: //生产准备检查
                    break;
                case 6: //转工计划接收
                    break;
                case 7: //滚动制造计划
                    break;
                default:
                    break;
            }
        },
        //保存任务
        save: function () {
            var bsVaild = $('#dgBaseForm').form('validate');
            if (bsVaild === false) {
                displayMessage("请填写必填项", false);
                return;
            }
            var params = {
                action: "SaveScheduledTaskData",
                scheduledTaskId: formPage.selectData == null ? '' : formPage.selectData.SCHEDULEDTASKID,
                taskName: $("#popddlTaskName").combobox("getText"),
                taskType: formPage.taskType
            }
            //获取基础配置里的数据
            var dgBaseFormData = $("#dgBaseForm").serializeArray();
            $.each(dgBaseFormData, function () {
                params[this.name] = this.value;
            });
            //获取任务选项里的数据并验证
            var formID = ""
            switch (formPage.taskType) {
                case 3: //同步现场台账
                    formID = "dgLineForm";
                    break;
                case 4: //预排制造计划
                    formID = "dgPreApsForm";
                    break;
                case 5: //生产准备检查
                    break;
                case 6: //转工计划接收
                    formID = "dgShipRevForm";
                    break;
                case 7: //滚动制造计划
                    formID = "dgApsForm";
                    break;
                default:
                    break;
            }
            if (formID !== "") {
                var vaild = $('#' + formID).form('validate');
                if (vaild === false) {
                    displayMessage("请填写必填项", false);
                    return;
                }
                var dgFormData = $('#' + formID).serializeArray();
                $.each(dgFormData, function () {
                    if (params[this.name] !== undefined) {
                        params[this.name] += "," + this.value;
                    } else {
                        params[this.name] = this.value;
                    }
                });
            }
            //提交保存
            page.post(page.ajaxUrl, params, true, function (result) {
                if (result.Result) {
                    $("#dg").dialog('options').returnData = result
                    $('#dg').dialog('close');
                }
                displayMessage(result.Message, result.Result);
            });
        }
    };

    $(function () {
        page.init();
    });
</script>
